var fs = require('fs')
var path = require('path')

function getJsFile(filePath, uplevel = '.') {
  let flist = []
  try {
    let res = fs.readdirSync(filePath)
    res.forEach((fname) => {
      let _path = path.join(filePath, fname)
      let stats = fs.statSync(_path)
      let isFile = stats.isFile()
      if (isFile && _path.substr(-3) == '.js') flist.push(uplevel + '/' + fname)
      let isDir = stats.isDirectory()
      if (isDir) flist = [...flist, ...getJsFile(_path, uplevel + '/' + fname)]
    })
    return flist
  } catch (e) {
    console.log('getJsFile > error:', e)
    return []
  }
}

var filePath = path.resolve('./')

let res = getJsFile(filePath)

console.log('res:', res)
